package ipdesk.model.analysis.action;

import java.util.List;

import ipdesk.model.analysis.bean.AnalysisSeminarBean;
import ipdesk.model.analysis.dao.AnalysisSeminarDao;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

import ecg.util.Time;


public class AnalysisSeminarAction extends ActionSupport implements Preparable, ModelDriven<AnalysisSeminarBean>
{
	private AnalysisSeminarBean analysisSeminarBean;
	private List<AnalysisSeminarBean> yearList;
	private List<AnalysisSeminarBean> analysisSeminarList;
	private List<AnalysisSeminarBean> analysisSeminarListByMonth;
	
	
	

	public String execute() throws Exception
	{
		
		// 1. 년도 셀렉트 박스 리스트를 가져온다.
		yearList = AnalysisSeminarDao.getInstance().getYears();
		
		
		// 2. 조회에 필요한 년도 파라메터가 없다면 올해로 검색한다.
		String selectedYear = "";
		
		if(analysisSeminarBean.getSelectedYear() == null || "".equals(analysisSeminarBean.getSelectedYear())){
			selectedYear = Time.getYear();
			analysisSeminarBean.setSelectedYear(selectedYear);
		}else{
			selectedYear = analysisSeminarBean.getSelectedYear();
		}
		
		analysisSeminarList = AnalysisSeminarDao.getInstance().getAnalysisSeminarList(selectedYear);
		
		
		return SUCCESS;
	}
	
	public String executeGetDaysResults() throws Exception
	{
		// 1. 페이지에서 가져온, 년도, 월에 따른 마지막 일자를 구한다.
		String selectedYear = "";
		String month		= "";
		int days			= 0;
		
		if(analysisSeminarBean.getSelectedYear() == null || "".equals(analysisSeminarBean.getSelectedYear())){
			selectedYear = Time.getYear();
			analysisSeminarBean.setSelectedYear(selectedYear);
		}else{
			selectedYear = analysisSeminarBean.getSelectedYear();
		}
		//System.out.println("selectedYear : "+selectedYear);
		if(analysisSeminarBean.getMonth() == null || "".equals(analysisSeminarBean.getMonth())){
			month = "01";
			analysisSeminarBean.setMonth(month);
		}else{
			month = analysisSeminarBean.getMonth();
		}
		//System.out.println("month : "+month);
		
		days = Time.getLastDay(selectedYear, month);
		analysisSeminarBean.setDays(String.valueOf(days));
		//System.out.println("days : "+days);
		
		// 2. 쿼리 요청
		
		analysisSeminarListByMonth = AnalysisSeminarDao.getInstance().getAnalysisSeminarListByMonth(analysisSeminarBean);
		//System.out.println("analysisSeminarListByMonth.size :: "+analysisSeminarListByMonth.size());
		return SUCCESS;
	}

	public void prepare() throws Exception {
		analysisSeminarBean = new AnalysisSeminarBean();
		
	}

	public AnalysisSeminarBean getModel() {

		return analysisSeminarBean;
	}

	public List<AnalysisSeminarBean> getYearList() {
		return yearList;
	}

	public List<AnalysisSeminarBean> getAnalysisSeminarList() {
		return analysisSeminarList;
	}
	
	public List<AnalysisSeminarBean> getAnalysisSeminarListByMonth() {
		return analysisSeminarListByMonth;
	}
}

